package com.zjuee.web.basic.dict.controller;

import com.zjuee.base.bean.response.R;
import com.zjuee.base.constant.Common;
import com.zjuee.base.model.common.basic.Dict;
import com.zjuee.service.basic.dict.DictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 字典web接口
 *
 * @author wu liang
 * @since 1.0
 */
@Slf4j
@RestController
@RequestMapping(path = Common.Service.ZJUEE_BASIC_DICT_URL_PREFIX, name = Common.Service.ZJUEE_BASIC_SERVICE_NAME)
public class DictController {

    @Resource
    private DictService dictService;

    @GetMapping("/findDict/{parentId}")
    public R<List<Dict>> findDictByDictType(@PathVariable("parentId") Long parentId) {
        try {
            List<Dict> dictList = dictService.findByParentId(parentId);
            if (null != dictList) {
                return R.ok(dictList);
            }
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
        return R.fail("Resource does not exist");
    }
}
